package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerDTO;
import com.qk.dto.customer.CustomerQueryDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import com.qk.vo.customer.CustomerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author kaoM1Jy
 * @date 2025/10/16 15:24
 * @description:
 */
@RestController
@RequestMapping("/customers")
@SuppressWarnings("all")
public class CustomerController {
    @Autowired
    private CustomerService customerService;


    @PutMapping
        public Result updateCustomer(@RequestBody Customer dto) {
        customerService.updateCustomer(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Integer id) {
        CustomerVO customer = customerService.getCustomerById(id);
        return Result.success(customer);
    }


    @PostMapping
    public Result addCustomer(@RequestBody CustomerDTO dto) {
        customerService.addCustomer(dto);
        return Result.success();
    }

    @GetMapping
    public Result getCustomerList(CustomerQueryDTO dto){
        PageResult<CustomerDO> result = customerService.getCustomerList(dto);
        return Result.success(result);
    }



}
